import AudioList from "@/utils/audio-list/main";
import VuexStore from "@/store";

import xiqiAudio from "@/assets/吸气.mp3";
import huqiAudio from "@/assets/呼气.mp3";
import ClickAudio from "@/assets/点击音效.mp3";

import yaqiAudio from "@/assets/压气.mp3";
export function setPlayerList(
  id: string,
  shijiIndex: number,
  type: "gedan" | "shiji",
  uid?: string
): Promise<typeof AudioList> {
  return new Promise((resolve) => {
    VuexStore.dispatch("sgb/getGeDanList", {
      type,
      id: shijiIndex,
      uid,
    }).then((res: any) => {
      console.log(res);
      const index = res.list.findIndex((item: any) => item._id === id);
      AudioList.audioList.setPlayerList(
        res.list.map((item: any) =>
          AudioList.transformPlayerList(item, {
            title: "mulu",
            src: "dmtUrl.adUrl",
            serial: "xuhao",
          })
        ),
        index
      );
      resolve(AudioList);
    });
  });
}

// 播放吸气声音
const audio = new Audio(huqiAudio);
const PLAYBACKRATE = 1;
export function playerHuQiAudio() {
  audio.src = huqiAudio;
  audio.playbackRate = PLAYBACKRATE;
  audio.play();
}
// 播放呼气声音
export function playerXiuQiAudio() {
  audio.src = xiqiAudio;
  audio.playbackRate = PLAYBACKRATE;
  audio.play();
}
// 播放压气声音
export function playerYaQiAudio() {
  audio.src = yaqiAudio;
  audio.playbackRate = PLAYBACKRATE;
  audio.play();
}

// 点击声音

export function playClickAudio() {
  audio.src = ClickAudio;
  audio.play();
}
